#Region " Imports "

Imports System
Imports System.Data
Imports BlazeApps.Library.Events
Imports BlazeApps.Library.Options

#End Region

Partial Class Usercontrols_Event_EventViewer
    Inherits UserControlBase

#Region " Enums, Memebers and Properties "

    Protected Property EventGuid() As Guid
        Get
            Return GetGuidFromVS("EventID")
        End Get
        Set(ByVal value As Guid)
            ViewState.Add("EventID", value)
        End Set
    End Property

#End Region

#Region " Page Events "

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        GetQueryStringValues()

        If Me.Page.IsPostBack = False Then
            SetViewed(EventGuid, False)
            LoadEvent()
            If IsPrintMeOrPopUpActive() = False Then
                LoadOptions()
            End If
        End If

        SetPageState()

    End Sub

#End Region

#Region " Save Data "


#End Region

#Region " Load Data "

    Private Sub LoadOptions()
        Dim Items As OptionDetail = OptionDetail.GetOptions(EventGuid)

        'Hide/Show Panels based on page settings
        Me.uxFavoritesPanel.Visible = (Items.AllowSubscriptions And EnableFavorites)
        Me.uxRaingPanel.Visible = (Items.AllowRanking And EnableRating)
        Me.uxCommentsPanel.Visible = (Items.AllowComments And EnableComments)
        Me.uxTagsPanel.Visible = (Items.AllowTags And EnableTags)
        Me.uxToolsPanel.Visible = (Items.AllowInfoTools And EnableTools)

        'Enable/Disable Panels based on page settings
        Me.uxFavoritesPanel.Enabled = (Items.AllowSubscriptions And EnableFavorites)
        Me.uxRaingPanel.Enabled = (Items.AllowRanking And EnableRating)
        Me.uxCommentsPanel.Enabled = (Items.AllowComments And EnableComments)
        Me.uxTagsPanel.Enabled = (Items.AllowTags And EnableTags)
        Me.uxToolsPanel.Enabled = (Items.AllowInfoTools And EnableTools)

    End Sub

    Private Sub LoadEvent()
        Dim item As EventDetail = EventDetail.GetEventDetail(EventGuid)

        Me.uxEventTitleLabel.Text = item.EventTitle
        Me.uxEventDetailsLiteral.Text = item.EventDetails
        Me.uxEventDateLabel.Text = String.Format("{0} at {1}, Created by {2}", FormatEventDate(item.EventDate), String.Format("{0:##}:{1:##} {2}", item.Hr, item.Min.ToString("00"), item.Meridian), String.Format("<a href=""{0}.aspx?pid=cp_profileview&userid={1}"">{1}</a>", AppPage, Membership.GetUser(item.UserID).UserName.ToString))

        SetPageTitle(item.EventTitle)

        If IsUserAuthenticated Then
            If IsAllowedEdit(item.UserID.ToString) Then
                Me.uxEditEventHyperLink.Visible = True
                Me.uxEditEventHyperLink.NavigateUrl = String.Format("{0}.aspx?pid=eve_addevent&id={1}", AppPage, EventGuid)
                Me.uxEditEventHyperLink.Text = "Edit"
            End If
        End If

        Me.uxFavorites.FavoriteType = BlazeApps.Library.Base.ItemType.Events
        Me.uxTags.TagType = BlazeApps.Library.Base.ItemType.Events
        Me.uxRating.Revision = 1

    End Sub

#End Region

#Region " Form Controls Events "

#End Region

#Region " Helpers and Methods "

    Protected Sub GetQueryStringValues()
        EventGuid = GetGuidFromQueryString("id")
    End Sub

    Private Sub SetPageState()

        If IsPrintMeOrPopUpActive() = True Then
            Me.uxCommentsList.Visible = False
            Me.uxCommentsList.HideData = True
            Me.uxTools.Visible = False
            Me.uxTools.HideData = True
            Me.uxRating.Visible = False
            Me.uxRating.HideData = True
            Me.uxFavorites.Visible = False
            Me.uxFavorites.HideData = True
            Me.uxTags.Visible = False
            Me.uxTags.HideData = True
        End If

    End Sub

    Private Function IsAllowedEdit(ByVal UserID As String) As Boolean
        Return (CurrentUserID = ConvertToGuid(UserID) OrElse IsEventModerator())
    End Function

#End Region

End Class
